package day021.tcp.demo7;

import org.apache.commons.io.IOUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.*;
import java.net.Socket;

public class TcpClient {
    private static final Logger LOGGER = LoggerFactory.getLogger("TcpClient客户端");

    public static void main(String[] args) throws IOException {
        Socket client = new Socket("127.0.0.1", 9090);
        FileInputStream fis = new FileInputStream("D:\\ideaProjects\\javase_code\\study-practice\\src" +
                "\\day021\\tcp\\files\\123.jpg");
        OutputStream netOutput = client.getOutputStream();
        IOUtils.copy(fis, netOutput);
        LOGGER.trace("文件上传完成！");

        client.shutdownOutput();

        BufferedReader br = new BufferedReader(new InputStreamReader(client.getInputStream()));
        String msg = br.readLine();
        LOGGER.trace("服务器返回消息：" + msg);

        br.close();
        netOutput.close();
        fis.close();
        client.close();

    }
}
